//
//  ActivityViewController.m
//  A_GOGO
//
//  Created by Liuiu on 16/1/16.
//  Copyright © 2016年 www.lanou3g.com. All rights reserved.
//

#import "ActivityViewController.h"
#import "UIColor+Wonderful.h"
#import "ActivityTableViewCell.h"
#import "HomeModel.h"
#import "NetworkHandler.h"
#import <UIImageView+WebCache.h>
#import <MMDrawerBarButtonItem.h>
#import <UIViewController+MMDrawerController.h>
#import "LeftDrawerViewController.h"

@interface ActivityViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, retain)UITableView *tableview;
@property (nonatomic, retain)NSMutableArray *arr;
@end

@implementation ActivityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor =[UIColor whiteColor];
    //导航栏设置
    self.navigationItem.title = @"热门活动";
    [self.navigationController.navigationBar setTitleTextAttributes:
     @{NSFontAttributeName:[UIFont fontWithName:@"Helvetica-Bold" size:21],
       NSForegroundColorAttributeName:[UIColor grayColor]}];
    self.navigationController.navigationBar.translucent = NO;
    //左边个人资料按钮
    UIButton *buttona = [UIButton buttonWithType:UIButtonTypeSystem];
    buttona.backgroundColor = [UIColor whiteColor];
    buttona.frame =  CGRectMake(0, 0, 38, 38);
    buttona.layer.cornerRadius = 19;
    [buttona setBackgroundImage:[UIImage imageNamed:@"personal"] forState:UIControlStateNormal];
    [buttona addTarget:self action:@selector(left:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:buttona];
    //右边"我的奖品"按钮
    UIBarButtonItem *item =[[UIBarButtonItem alloc]initWithTitle:@"我的奖品" style: UIBarButtonItemStylePlain target:self action:@selector(right:)];
    self.navigationItem.rightBarButtonItems = @[item];
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor doderBlue];
    
//***** 创建tableView
    _tableview =[[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    _tableview.backgroundColor = [UIColor whiteColor];
    _tableview.delegate =self;
    _tableview.dataSource = self;
    
    [self.view addSubview: _tableview];
    [_tableview release];
//    创建tableview重用池
    [_tableview registerClass:[ActivityTableViewCell class] forCellReuseIdentifier:@"cell"];
    
    [self data];
    
     

    
}
- (void)data
{
    NSString *sta =@"http://open.youxiduo.com/activity/ask-list/?appname=yxdjqb&os=ios&debug=beta&source=f634afb2d58f19820b59a9ab998dfd3e&pageSize=10&pageIndex=1&version=3.4.0";
    [NetworkHandler GETWithURL:sta completion:^(id result) {
        
        self.arr =result[@"result"][@"doingList"];
        self.arr = [HomeModel modelHanderWithArray:_arr];
        
        [_tableview reloadData];
        NSLog(@"%@",_arr);
    }];
    
    
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _arr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ActivityTableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    HomeModel *c =_arr[indexPath.row];
    [cell.image sd_setImageWithURL:[NSURL URLWithString:c.url]];
    cell.title.text = c.title;
    cell.startTime.text = c.startTime;
    cell.endTime.text = c.endTime;
    
   
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 210;
}


- (void)right:(UIBarButtonItem *)btn
{
    
}
- (void)left:(UIBarButtonItem *)btn
{
    NSLog(@"个人资料");
    [self.mm_drawerController toggleDrawerSide:MMDrawerSideLeft animated:YES completion:^(BOOL finished) {
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
